package com.meu.prontuario.database;

import java.util.ArrayList;
import java.util.List;

import com.meu.prontuario.util.Saumun;
import com.meu.prontuario.util.Year;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class SAUMUN extends SQLiteOpenHelper {

	private static final String TABLE = "SAUMUN" +Year.getInstance().getYear()+ ".db";
	private static final int VERSION  = 1;
	
	public SAUMUN(Context context) {
		super(context, TABLE, null, VERSION);
	}
	
	public SAUMUN(Context context, String name, CursorFactory factory, int version) {
		super(context, name, factory, version);
		
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		
		
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		
		
	}
	
	public void insert(Saumun saumun){
		
	}
	
	public List<Saumun> getList(){
		List<Saumun> saumuns = new ArrayList<Saumun>();
		Cursor cursor = getReadableDatabase().query(TABLE, null, null, null, null, null, null);
		
		while (cursor.moveToNext()){
			
		}
		cursor.close();
			
		return saumuns;		
	}
	
	public Saumun getItemPorId(Long id){
		 Saumun sanmun = new Saumun();
		
		Cursor cursor = getWritableDatabase().query(TABLE, null,"id = ?",new String []{}/*adulto.getId().toString()}*/,null,null, null);
		cursor.moveToFirst();
		
		return sanmun;
	}
	
	public void change(Saumun saumun){
		ContentValues values = new ContentValues();
			
		getWritableDatabase().update(TABLE, values,"id = ?",new String [] {});
	}
	
	public void delete(Saumun saumun){
		getWritableDatabase().delete(TABLE, "id = ?",new String []{});
	}
}
